﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>

<?php	

	include("inc/joomlaInt.php");
	include("inc/inc_configuration.php");
	
if ($jUser==0)
{
	echo "Bitte zuerst einloggen!";
}
else
{
	$team=$_GET["team"];
	$liga=$_GET["liga"];
	
	$q="SELECT type FROM $tbl_leagues WHERE id=$liga";
	$qe=mysql_query($q);
	$qeo=mysql_fetch_object($qe);
	
	$type=$qeo->type;
	
	if ($matchday=="")
	{
		$matchday=1;
	}
	
	$q="SELECT name FROM $tbl_teams WHERE id=$team";
	$qe=mysql_query($q);
	$qeo=mysql_fetch_object($qe);
	
	$name=$qeo->name;
	
	$q="SELECT name FROM $tbl_leagues WHERE id=$liga";
	$qe=mysql_query($q);
	$qeo=mysql_fetch_object($qe);
	
	$lname=$qeo->name;
	
	echo "	<h1>$name</h1>
			<h2>$lname</h2>";
	
	echo "<table id='tborder' bgcolor='#DADADA'>
			<tr id='tabelle'>";
	
	
				
	echo "		<th>Spieltag</th>";
	
	if ($type!=1)
	{
		echo "<th>Gruppe</th>";
	}		
	
	echo "		<th>Heim</th>
				<th></th>
				<th></th>
				<th></th>
				<th></th>
				<th></th>
				<th>Gast</th>
				<th>Datum</th>
				<th></th>
			</tr>";
	
	if ($type==1)
	{
		$mq=	"SELECT 		m1.id AS mId, 
								m1.homeG AS hG,
								m1.guestG AS gG,
								m1.playdate AS pd,
								m1.matchday AS spieltag, 
								m1.homeT AS hTi, 
								m1.guestT AS gTi, 
								t1.name AS hTn, 
								t2.name AS gTn,
								m1.homeC AS hC,
								m1.guestC AS gC,
								m1.free AS free,
								lp.path AS path,
								l.id AS leagueId,
								l.name AS ligaName
								
							FROM $tbl_matches m1, $tbl_teams t1, $tbl_teams t2, $tbl_lt lt, $tbl_leagues l, $tbl_leaguepics lp, $tbl_season s
							
							WHERE
							(t1.id=$team AND
							m1.homeT=t1.id AND
							m1.guestT=t2.id AND
							m1.leagueId=lt.leagueId AND
							lt.leagueId=l.id AND
							l.picId=lp.id AND
							l.seasonId=s.id AND
							s.active=1 AND
							l.id=$liga AND
							lt.teamId=t1.id)
							OR
							(t2.id=$team AND
							m1.homeT=t1.id AND
							m1.guestT=t2.id AND
							m1.leagueId=lt.leagueId AND
							lt.leagueId=l.id AND
							l.picId=lp.id AND
							l.seasonId=s.id AND
							s.active=1 AND
							l.id=$liga AND
							lt.teamId=t2.id)
							ORDER BY leagueId ASC, spieltag ASC
						";
	}
	else
	{
		$mq=	"SELECT 		m1.id AS mId, 
								m1.homeG AS hG,
								m1.guestG AS gG,
								m1.playdate AS pd,
								m1.matchday AS spieltag, 
								m1.homeT AS hTi, 
								m1.guestT AS gTi, 
								t1.name AS hTn, 
								t2.name AS gTn,
								m1.homeC AS hC,
								m1.guestC AS gC,
								m1.free AS free,
								lp.path AS path,
								l.id AS leagueId,
								l.name AS ligaName,
								lg.groupName AS gname
								
							FROM $tbl_matches m1, $tbl_teams t1, $tbl_teams t2, $tbl_gt gt, $tbl_lg lg, $tbl_leagues l, $tbl_leaguepics lp, $tbl_season s
							
							WHERE
							
							
							(t1.id=$team AND
							m1.homeT=t1.id AND
							m1.guestT=t2.id AND
							m1.leagueId=l.id AND
							m1.stageId=lg.id AND
							lg.leagueId=l.id AND
							l.picId=lp.id AND
							l.seasonId=s.id AND
							s.active=1 AND
							l.id=$liga AND
							gt.teamId=t1.id AND
							gt.groupId=lg.id)
							OR
							(t2.id=$team AND
							m1.homeT=t1.id AND
							m1.guestT=t2.id AND
							m1.leagueId=l.id AND
							m1.stageId=lg.id AND
							lg.leagueId=l.id AND
							l.picId=lp.id AND
							l.seasonId=s.id AND
							s.active=1 AND
							l.id=$liga AND
							gt.teamId=t1.id AND
							gt.groupId=lg.id)

							ORDER BY leagueId ASC, spieltag ASC
						";
	}
	
	$mqe=mysql_query($mq);
				
	while ($row=mysql_fetch_object($mqe))
	{
		$mId=$row->mId;
		$tHi=$row->hTi;
		$tGi=$row->gTi;
		$tHn=$row->hTn;
		$tGn=$row->gTn;
		$hG=$row->hG;
		$gG=$row->gG;
		$playdate=$row->pd;
		$spieltag=$row->spieltag;
		$liganame=$row->ligaName;
		
		$b="";
		
		if ($type!=1)
		{
			$gname=$row->gname;
		}
		
		if ($playdate!="")
		{
			$playdate = date("d.m.Y - H:i", $playdate);
		}
		
		$free=$row->free;

		if ($free>=2)
		{
			$cHi=$row->hC;
			$cGi=$row->gC;
			
			if ($free==3)
			{
				$b="<a href='spielbericht.php?matchID=$mId&type=2'><img src='img/bericht.png' alt='Spielbericht'></a>";
			}
			
			$uHSql="	SELECT username, u.id AS uid FROM $tbl_combinations c, $tbl_users u
								WHERE
								(c.id=$cHi) AND
								(c.userId=u.id)";
			$uGSql="	SELECT username, u.id AS uid FROM $tbl_combinations c, $tbl_users u
								WHERE
								(c.id=$cGi) AND
								(c.userId=u.id)";
								
			if ($free==3 OR $free==2)
			{
				
							
				$uHq = mysql_query($uHSql);
				$uGq = mysql_query($uGSql);
				
				$uHnq = mysql_fetch_object($uHq);
				$uHn = $uHnq->username;
				$uHi = $uHnq->uid;
				$uHn = "<a href='profil.php?id=$uHi'>$uHn</a>";
				
				$uGnq = mysql_fetch_object($uGq);
				$uGn = $uGnq->username;
				$uGi = $uGnq->uid;
				$uGn = "<a href='profil.php?id=$uGi'>$uGn</a>";
			}
			else
			{
				if ($cHi==0)
				{
					$uHn="Gewertet";
				}
				else
				{
					$uHq = mysql_query($uHSql);
					$uHnq = mysql_fetch_object($uHq);
					$uHn = $uHnq->username;
					$uHi = $uHnq->uid;
					$uHn = "<a href='profil.php?id=$uHi'>$uHn</a>";
				}
				
				if ($cGi==0)
				{
					$uGn="Gewertet";
				}
				else
				{
					$uGq = mysql_query($uGSql);
					$uGnq = mysql_fetch_object($uGq);
					$uGn = $uGnq->username;
					$uGi = $uGnq->uid;
					$uGn = "<a href='profil.php?id=$uGi'>$uGn</a>";
				}
			}
			
		}
		else
		{
			//Combinations suchen
			$uHSql="	SELECT username AS uHn, c.id AS hC, u.id AS uHi FROM $tbl_combinations c, $tbl_users u
							WHERE
							(c.teamId=$tHi) AND
							(c.active=1) AND
							(c.userId=u.id)";
			$uGSql="	SELECT username AS uGn, c.id AS gC, u.id AS uGi FROM $tbl_combinations c, $tbl_users u
					WHERE
					(c.teamId=$tGi) AND
					(c.active=1) AND
					(c.userId=u.id)";
					
			$uHq = mysql_query($uHSql);
			$uGq = mysql_query($uGSql);

			
			$cH = mySQL_num_rows($uHq);
			$cG = mySQL_num_rows($uGq);
			
			if ($cH == 1)
			{
				$uHnq = mysql_fetch_object($uHq);
				$uHn = $uHnq->uHn;
				$uHi = $uHnq->uHi;
				$uHn = "<a href='profil.php?id=$uHi'>$uHn</a>";
				
			}
			else
			{
				$uHn = "(-)";
			}
			
			if ($cG == 1)
			{
				$uGnq = mysql_fetch_object($uGq);
				$uGn = $uGnq->uGn;
				$uGi = $uGnq->uGi;
				$uGn = "<a href='profil.php?id=$uGi'>$uGn</a>";
				
			}
			else
			{
				$uGn = "(-)";
			}
		}
		
		if ($hG=="")
		{
			$hG=="-";
		}
		if ($gG=="")
		{
			$gG=="-";
		}
		
		$span=10;
		
		echo "	<tr>
					<td>$spieltag. Spieltag</td>";
		if ($type!=1)
		{
			echo "<td>$gname</td>";
			$span++;
		}		
		echo "		<td><a href='spiele_team.php?team=$tHi&liga=$liga'>$tHn</a><br>$uHn</td>
					<td><a href='team_kader.php?team=$tHi'><img src='img/logos/",$tHi,".png' width='35' height='35' alt=''></a></td>
					<td>$hG</td>
					<td>:</td>
					<td>$gG</td>
					<td><a href='team_kader.php?team=$tGi'><img src='img/logos/",$tGi,".png' width='35' height='35' alt=''></a></td>
					<td><a href='spiele_team.php?team=$tGi&liga=$liga'>$tGn</a><br>$uGn</td>
					<td>$playdate</td>
					<td>$b</td>
				</tr>";	
	}
	
	echo "<tr id='tabelle'><th colspan='$span'> </th></tr></table>";
	
	echo '<br><br><center><a href="javascript:window.history.back()" class="button zurueck">Zurück</a></center>';
}	
?>

</body>
</html>